package com.bitnpulse.dev2.jjh.engstudybook_free.common;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;

//import com.pantech.app.planner.PlannerStaticInfo;

import android.text.format.Time;
import android.util.Log;

public class Sun {

	static int nDaysList[] = {31 , 28 , 31 , 30 ,31 ,30, 31, 31 , 30 ,31 ,30 ,31}; 

	
	public static int  getDays(int year, int month ) {
	if (month  == 2){

	 if(((year%4 == 0)&&(year%100 != 0)) ||(year%400 == 0)){
	  return(29);
	 }
	  
	 
	 }

	  return(nDaysList[month-1]);
	 }

	
	

	public static int getStartDay(int year, int month){
	 int totalDays;

	 totalDays = (year * 365);

	 totalDays +=(year-1)/4;
	 totalDays -=(year-1)/100;
	 totalDays +=(year-1)/400;


	 for(int i=1; i<month;i++){
	  totalDays +=getDays(year, i);
	 }

	 return(totalDays % 7 );
	}

	 


	static void printMonth(int year, int month, int nDays, int startDay){
	 int i, column=0;
	 for(i=0;i<startDay;i++){
	  System.out.print("    ");

	  column++;
	 }
	 for(i=1;i<=nDays;i++){

	  if(i < 10) {

	   System.out.print("  " + i + " ");
	  }else{
	   System.out.print(" " + i + " ");
	  }
	  column++;

	  if(column == 7) {

	   column = 0;
	   
	  }
	 }
	}


	
	public static List<List<Integer>> week_days(int year, int month, int day){
		Calendar cal = Calendar.getInstance();
		
		cal.set(year, month-1, day);
		
		List<Integer> years = new ArrayList<Integer>();
		List<Integer> months = new ArrayList<Integer>();
		List<Integer> days = new ArrayList<Integer>();
		List<Integer> weeks = new ArrayList<Integer>();
		
		switch(cal.get(cal.DAY_OF_WEEK)) {
			case 1:
				cal.add(cal.DATE,0);
				break;
			case 2:
				cal.add(cal.DATE,-1);
				break;
			case 3:
				cal.add(cal.DATE,-2);
				break;
			case 4:
				cal.add(cal.DATE,-3);
				break;
			case 5:
				cal.add(cal.DATE,-4);
				break;
			case 6:
				cal.add(cal.DATE,-5);
				break;
			case 7:
				cal.add(cal.DATE,-6);				
				break;
		}
		
		for(int i =0; i < 7; i++){
			years.add(cal.get(Calendar.YEAR));
			months.add(cal.get(cal.MONTH)+1);
			days.add(cal.get(cal.DATE));
			weeks.add(cal.get(Calendar.WEEK_OF_MONTH));
			cal.add(cal.DATE,1);
		}
		
		 List<List<Integer>> result =  new ArrayList<List<Integer>>();
	
		 result.add(years);
		 result.add(months);
		 result.add(days);
		 result.add(weeks);
			
		 return result;
	}
	
	
	public static List<Integer> getnextday(int year, int month, int day, int date){
		
		Calendar cal = Calendar.getInstance();
		
		cal.set(year, month-1, day);
		
		cal.add(cal.DATE, date);
		
		List<Integer> result = new ArrayList<Integer>();
		
		result.add(cal.get(Calendar.YEAR));
		result.add(cal.get(cal.MONTH)+1);
		result.add(cal.get(cal.DATE));
		
		return result;
	}
	
	public static List<Integer> getpreday(int year, int month, int day, int date){
		
		Calendar cal = Calendar.getInstance();
		
		cal.set(year, month-1, day);
		
		cal.add(cal.DATE, -date);
		
		List<Integer> result = new ArrayList<Integer>();
		
		result.add(cal.get(Calendar.YEAR));
		result.add(cal.get(cal.MONTH)+1);
		result.add(cal.get(cal.DATE));
		
		return result;
	}
	
	public static String getMonth(int m){
		String month = "";
		
		switch (m) {
		case 1:
			month = "January";
			break;
		case 2:
			month = "February";
			break;
		case 3:
			month = "March";
			break;
		case 4:
			month = "April";
			break;
		case 5:
			month = "May";
			break;
		case 6:
			month = "June";
			break;
		case 7:
			month = "July";
			break;
		case 8:
			month = "August";
			break;
		case 9:
			month = "September";
			break;
		case 10:
			month = "October";
			break;
		case 11:
			month = "November";
			break;
		case 12:
			month = "December";
			break;
		}
		return month;
	}
	
//	public static int getDday(int year, int month, int date){
//		
//		int result = 0;
//		
//		
//		  try {
////		      year = Integer.parseInt(args[0]);
////		      month = Integer.parseInt(args[1]);
////		      date = Integer.parseInt(args[2]);
//
//		      Calendar today = Calendar.getInstance();
//		      Calendar cal = Calendar.getInstance();
//		      cal.set(year, month - 1, date);
//		      
//		      
//		      long delta = cal.getTimeInMillis() - today.getTimeInMillis();
//		      cal.setTimeInMillis(delta);
//
//		      year = cal.get(Calendar.YEAR) - 1970;
//		      date = cal.get(Calendar.DAY_OF_YEAR) - 1;
//		      
//		    }
//		    catch (NumberFormatException e) {
//		    	Log.d("Planner", ""+e);
//		    }
//		
//		
//		return result;
//	}
	
	
//	public static int getDday(long timemilli){
//		int result;
//		
//		  Calendar today = Calendar.getInstance();
//		  
//		  result = Time.getJulianDay(today.getTimeInMillis(), PlannerStaticInfo.time_gto) - Time.getJulianDay(timemilli, PlannerStaticInfo.time_gto);
//		
//		return result;
//	}

		



}
